/**
圆形菜单-工作台模式使用

属性
  menu:Array,例如：
  /src/mock/user.js 中的模拟菜单
 */
<template>
  <div>
    <div class="main-btn" @click="collapse = !collapse">
      <i :class="collapse ? 'el-icon-arrow-down' : 'el-icon-arrow-up'" />
    </div>
    <template v-if="!collapse">
      <div
        class="btn"
        v-for="item in menu"
        :key="item.code"
        @mouseover="showSubMenu = item.path"
        @click="menuClick(item)"
      >
        <router-link v-if="!item.children && item.type==3" :to="item.path">
          <div class="icon">
            <i :class="item.icon ? item.icon : 'el-icon-document'" />
          </div>
          <div class="title">{{ item.title }}</div>
        </router-link>
        <div v-else-if="!item.children && item.type==4" @click="call(item)">
          <div class="icon">
            <i :class="item.icon ? item.icon : 'el-icon-document'" />
          </div>
          <div class="title">{{ item.title }}</div>
        </div>
        <div v-else>
          <div class="icon">
            <i :class="item.icon ? item.icon : 'el-icon-document'" />
          </div>
          <div class="title">{{ item.title }}</div>
        </div>
        <div class="sub-menu" v-if="item.children && item.path == showSubMenu">
          <div class="sub-btn" v-for="sub in item.children" :key="sub.code">
            <router-link v-if="sub.type==3" :to="sub.path">
              <div class="sub-icon">
                <i :class="sub.icon ? sub.icon : 'el-icon-document'" />
              </div>
              <div class="sub-title">{{ sub.title }}</div>
            </router-link>
            <div v-if="sub.type==4" @click="call(sub.click)">
              <div class="sub-icon">
                <i :class="sub.icon ? sub.icon : 'el-icon-document'" />
              </div>
              <div class="sub-title">{{ sub.title }}</div>
            </div>
          </div>
        </div>
      </div>
    </template>
  </div>
</template>

<script>
export default {
  props:{
    menu:{type:Array,required: true,}
  },
  data() {
    return {
      collapse: true,
      showSubMenu: "",
    };
  },
  methods:{
    test(e){
      console.log('test',e)
    },
    call(item){
      if (typeof item != 'undefined'){
        if (typeof item.click == 'string'){
          eval("this."+item.click+"()")
        }else{
          item.click()
        }
      }
    },
    menuClick(item){
      this.$store.commit('setActiveMenu',item.path)
    }
  },
};
</script>

<style lang="less" scoped>
.main-btn {
  height: 30px;
  width: 60px;
  border-radius: 15px;
  background-color: #4590bf;
  cursor: pointer;
  text-align: center;
  line-height: 30px;
  color: #fff;
  font-size: 30px;
  opacity:0.6;
}
.main-btn:hover {
  background-color: rgb(148, 215, 242, 0.1);
  color: #000;
}
.btn {
  margin-top: 10px;
  display: flex;
  .icon {
    height: 60px;
    width: 60px;
    border-radius: 30px;
    background-color: #4590bf;
    cursor: pointer;
    text-align: center;
    line-height: 60px;
    color: #fff;
    font-size: 32px;
    opacity:0.6;
  }
  .title {
    width: 60px !important;
    font-weight: bold;
    text-align: center;
    font-size: 12px;
  }
  .sub-menu {
    display: flex;
    .sub-btn {
      margin-left: 10px;
      .sub-icon {
        height: 60px;
        width: 60px;
        border-radius: 30px;
        background-color: #4590bf;
        cursor: pointer;
        text-align: center;
        line-height: 60px;
        color: #fff;
        font-size: 24px;
        opacity:0.6;
      }
      .sub-title {
        width: 60px !important;
        height: 16px;
        font-weight: bold;
        text-align: center;
        font-size: 12px;
      }
    }
  }
}
.btn:hover {
  .icon {
    background-color: rgb(148, 215, 242, 0.1);
  }
  .title {
    color: #4590bf;
  }
}

.sub-menu .sub-btn:hover {
  .sub-icon {
    background-color: rgb(148, 215, 242, 0.1);
  }
  .sub-title {
    color: #4590bf;
  }
}
</style>
